<template>
  <div class="page-container">
    <SearchPanel @change="handleSearchPanelChange">
      <el-form
        ref="queryForm"
        class="query-more-form"
        size="mini"
        label-width="100px"
        :model="query"
      >
        <el-row :gutter="21">
          <el-col :span="16">
            <el-form-item label="综合条件">
              <el-input
                v-model="query.query"
                class="search-ipt"
                placeholder="请输入查询条件"
                maxlength="255"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="10">
            <el-form-item label="时间区间">
              <el-date-picker
                v-model="query.startTime"
                type="datetimerange"
                size="mini"
                range-separator="-"
                start-placeholder="开始"
                end-placeholder="结束"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="任务部门">
              <el-select
                class="w-100"
                v-model="query.deptName"
                placeholder="请选择任务部门"
                clearable
              >
                <el-option
                  v-for="item in department"
                  :key="item.code"
                  :value="item.sysDeptVo.deptName"
                  :label="item.sysDeptVo.deptName"
                />
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="4" class="btn-col">
            <el-button size="mini" class="search-btn" @click="select"
              >查询</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </SearchPanel>
    <div class="table-container">
      <div class="table-tools-panel table-flex-row">
        <el-button class="flush-btn" size="mini" icon="el-icon-refresh"
          >刷新</el-button
        >
        <div>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-set-up"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-share"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-printer"
          ></el-button>
        </div>
      </div>
      <div class="table-list-panel">
        <el-table
          v-loading="tableLoading"
          border
          size="small"
          :data="tableData"
          :height="isShow ? 'calc(100vh - 410px)' : 'calc(100vh - 335px)'"
          style="width: 100%"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column
            prop="unitName"
            label="巡查对象名称"
            show-overflow-tooltip
          />
           <el-table-column
            prop="categoryCompleteName"
            label="检查事项全称"
            show-overflow-tooltip
          />
          <el-table-column prop="startTime" label="巡检时间区间" width="260">
            <template slot-scope="scope">
              <div>
                {{ parseTime(scope.row.beginTime) }}~{{
                  parseTime(scope.row.endTime)
                }}
              </div></template
            >
          </el-table-column>
         
          <el-table-column
            prop="deptName"
            label="检查部门"
            show-overflow-tooltip
          />
          <el-table-column
            prop="patrolUserNumber"
            label="执法人员数"
            width="100"
            show-overflow-tooltip
          />
           <el-table-column
            prop="planNumber"
            label="计划巡检次数"
            width="100"
            show-overflow-tooltip
          />
          <el-table-column
            prop="completeNumber"
            label="实际完成次数"
            width="100"
            show-overflow-tooltip
          />
          <el-table-column prop="status" label="完成情况" show-overflow-tooltip>
            <template slot-scope="scope">
              <template v-if="scope.row.status == 0">
                <span>未完成</span>
              </template>
              <template v-if="scope.row.status == 1">
                <span>已完成</span>
              </template>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="90" fixed="right">
            <template slot-scope="scope">
              <el-button
                class="table-inner-btn"
                type="text"
                size="mini"
                @click.native="handleDetail(scope.row)"
                >详情</el-button
              >
              <el-button
                class="table-inner-btn"
                type="text"
                size="mini"
                @click.native="handleUpdate(scope.row)"
                >记录</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-panel">
        <Pagination
          :total="query.total"
          :page.sync="query.pageNum"
          :limit.sync="query.pageSize"
          @pagination="initData"
        />
      </div>
    </div>

    <InspectionItemDetailsDialog
      :dialogVisible="DetailsDialog"
      :caseId="caseId"
      @closeDialog="DetailsDialog = false"
    />

    <ReportDialog
      :dialogVisible="ReportDialogDialog"
      :taskId="taskId"
      @closeDialog="ReportDialogDialog = false"
    />
  </div>
</template>

<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import { getList, getTwo } from "@/api/system/inspectionItemRecord";
import { parseTime } from "@/utils/index";
import InspectionItemDetailsDialog from "./components/inspectionItemDetailsDialog";
import ReportDialog from "./components/ReportDialog";
import { detailsUrl } from "@/utils/changeUrl";

export default {
  name: "CaseDealDispatch",
  components: {
    SearchPanel,
    Pagination,
    InspectionItemDetailsDialog,
    ReportDialog
  },
  data() {
    return {
      query: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        query: ""
      },
      tableLoading: false,
      DetailsDialog: false,
      ReportDialogDialog: false,
      tableData: [],
      department: [],
      isShow: true,
      taskId: null,
      caseId: {}
    };
  },
  created() {
    this.initData();
  },
  methods: {
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    parseTime,
    initData() {
      this.select();
    },
    select() {
      this.tableLoading = true;
      getList(this.query)
        .then(result => {
          this.tableLoading = false;
          this.query.total = result.total;
          this.tableData = result.rows;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    handleDetail(val) {
      this.DetailsDialog = true;
      getTwo(val.id).then(res => {
        this.caseId = res.data;

        // this.checkTableData=this.form.units
        // this.tableMatterData1=this.form.users
      });
    },
    handleUpdate(val) {
      this.ReportDialogDialog = true;
      this.taskId = val.id;
    }
  }
};
</script>

<style lang="scss" scoped></style>
